package StudyCode.summary.textfile;

import java.io.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class FileReadToString {
	public static void main(String[] argv) throws Exception {
		String filePath = "E:/Copy/test1.txt";
		System.out.println(file_read(filePath));
	}

	public static String file_read(String filePath) {
		try {
			FileInputStream fin = new FileInputStream(new File(filePath));
			String ret = convertStreamToString(fin);
			fin.close();
			return ret;
		} catch (Exception e) {
			return "";
		}
	}

	public static String convertStreamToString(InputStream is)
			throws Exception {
		BufferedReader reader = new BufferedReader(
				new InputStreamReader(is));
		StringBuilder sb = new StringBuilder();
		String line = null;
		while ((line = reader.readLine()) != null) {
			sb.append(line).append("\n");
		}
		reader.close();
		return sb.toString();
	}
}
